package com.ykc.demo.AOP;

import com.ykc.proxy.AspectProxy;
import com.ykc.spring.Aspect;
//import com.sun.org.slf4j.internal.Logger;
//import com.sun.org.slf4j.internal.LoggerFactory;

import java.lang.reflect.Method;

//@Aspect(pkg = "com.com.ykc.demo.controller",cls = "Controller")
public class TimeAop extends AspectProxy {

//    private static final Logger LOGGER = LoggerFactory.getLogger(AspectProxy.class);

    private long begin;

    /**
     * 切入点判断
     */
    @Override
    public boolean intercept(Method method, Object[] params) throws Throwable {
        return method.getName().equals("test");
    }

    @Override
    public void before(Method method, Object[] params) throws Throwable {
        System.out.println("---------- begin ----------");
        begin = System.currentTimeMillis();
        System.out.println(begin);
    }

    @Override
    public void after(Method method, Object[] params) throws Throwable {
        System.out.println(String.format("time: %dms", System.currentTimeMillis() - begin));
        System.out.println("----------- end -----------");
    }

}
